package org.example.controller;

import org.apache.ibatis.annotations.Param;
import org.example.pojo.Volunteer;
import org.example.pojo.activeMap;
import org.example.utils.R;
import org.example.service.VolunteerDataAnalyzeService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;

/**
 * @Description: 数据分析
 * @Author:曹震
 * @Date: 2024/12/3 14:25
 */
@RestController
@CrossOrigin
@RequestMapping("analyze")
public class VolunteerAnalyze {
    @Resource
    private VolunteerDataAnalyzeService service;
    //志愿者排行
    @GetMapping("sortVolunteers")
    public R sortVolunteers(){
        List <Volunteer> volunteers = service.sortVolunteers();
        return R.successful(null, volunteers);
    }
    //得到排行榜上的志愿者详细信息。包括任务
    @GetMapping("listTask")
    public R listVolunteerTask(@RequestParam String volunteerId){
        Volunteer volunteer = service.listVolunteerTask(volunteerId);
        if (volunteer==null){
            return R.empty("没有找到该志愿者", null);
        }
        return R.successful(null, volunteer);
    }
   //图的成列
    @GetMapping("listMap")
    public R shorMap(@RequestParam String volunteerId){
        String s = service.listMap(volunteerId);
        if (s.isEmpty()){
            return R.empty("数据有错", null);
        }
        return R.successful("查询成功", s);
    }
//活跃度的统计，所有
    @GetMapping("activeMap")
    public  R  activeMap(){
    List<Map<String, Integer>> maps = service.showActiveMap();
    return R.successful("成功",maps);
}
    @GetMapping("getRating")
    public R getRating(){
        Map<String,Integer> maps = service.showRating();
        if(maps.isEmpty()){
            return R.empty("数据获取失败",null);
        }else{
            return R.successful("成功",maps);
        }
    }
    @GetMapping("getVolunteerCountByMonth")
    public R getVolunteerCountByMonth(){
        String str = service.getVolunteerCountByMonth();
        return R.successful("返回成功",str);
    }
    @GetMapping("getVolunteerCountByWeek")
    public R getVolunteerCountByWeek(@Param("data")String data){
        String str = service.getVolunteerCountByWeek(data);
        return R.successful("查询成功",str);
    }
    //获取今日注册志愿者的信息,
    @GetMapping("getVolunteerTodayRegister")
    public R getVolunteerTodayRegister(){
        List<Volunteer> volunteerList = service.getVolunteerTodayRegisterList();
        return R.successful(null,volunteerList);
    }
}
